<?php

define('ACC',true);

require ('../includes/init.php');
require ('left.php');
$goodsbox = new GoodsboxModel();

if(isset($_SESSION['user_id']) && isset($_SESSION['username'])){
	$smarty->assign('SESSION', $_SESSION);
}

if(isset($_GET['act'])){
	$category = new CategoryModel();
	$search = trim($_GET['act']);
	if($search == 'hot' || $search == 'best' || $search == 'new'){
		
		$rowCount = $goodsbox->getRowCount3($search);
		$pageSize = 12;
		
		$category->setMessage($rowCount, $pageSize);
		$pageCount = $category->getPageCount();
		
		if($pageCount <= 5){
			$category->setMaxPageSize($pageCount);
		}else{
			$category->setMaxPageSize(5);
		}
		
		if(isset($_POST['pageNow'])){
			
			$pageNow = $_POST['pageNow'] + 0;
			if($pageNow <= 0){
				$pageNow = 1;
			}else if($pageNow > $pageCount){
				$pageNow = $pageCount;
			}
		}else{
			$pageNow = 1;
		}
	
		$category->setPageNow($pageNow);
		
		$navigate = $category->getFenyeCode();
		
		$smarty->assign('pageNow', $pageNow);
		$smarty->assign('firstPage', 1);
		$smarty->assign('lastPage', $pageCount);
		$smarty->assign('pageCount', $pageCount);
		$smarty->assign('navigate', $navigate);
		
		
		if($search == 'hot'){
			$action = '热门推荐';
		}else if($search == 'best'){
			$action = '精品推荐';
		}else if($search == 'new'){
			$action = '新品推荐';
		}
		
		if(isset($_POST['sort']) && $_POST['sort'] != ''){
		
			$sort = trim($_POST['sort']);
			$sort_value = $sort;
			$sort = explode("+", $sort);
			if(!isset($sort[0])){
				$sort[0] = '';
			}else if(!isset($sort[1])){
				$sort[1] = '';
			}

			$goods = $goodsbox->get_goods_sort($search, $sort, $pageNow, $pageSize);

			$smarty->assign('goods', $goods);
			$smarty->assign('sort_value', $sort_value);
			$smarty->assign('sort', $sort);
		
		}else{
		
			$goods = $goodsbox->get_goods($search, $pageNow, $pageSize);
			$smarty->assign('goods', $goods);
		
		}
		
		$smarty->assign('search', $search);
		$smarty->assign('ur_here', '当前位置:&nbsp;<a href=".">首页</a><code>&nbsp;&gt;&nbsp;</code>' . $action);
		$smarty->display('./front/goodsbox.html');
	}
	
}

















